package tools

import (
	"fmt"
	"net"
)

func GetFreePort() string {
	addr, err := net.ResolveTCPAddr("tcp", "localhost:0")
	if err != nil {
		return ""
	}

	l, err := net.ListenTCP("tcp", addr)
	if err != nil {
		return ""
	}
	defer l.Close()
	return fmt.Sprintf(":%d", l.Addr().(*net.TCPAddr).Port)
}
